package com.fouram.core.enums;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

/**
 * 是否枚举
 */
public enum YesOrNoEnum {

	YES("1", "是"), NO("0", "否");

	private String code;
	private String name;

	private YesOrNoEnum(String code, String name) {
		this.code = code;
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}

	public static String getNameByCode(String code) {
		for (YesOrNoEnum it : YesOrNoEnum.values()) {
			if (it.getCode().equals(code)) {
				return it.getName();
			}
		}
		return null;
	}

	public static List<Map<String, String>> toMapList(){
		List<Map<String, String>> list = Lists.newArrayList();
		for (YesOrNoEnum it : YesOrNoEnum.values()) {
			Map<String, String> map = Maps.newHashMap();
			map.put("code", it.getCode());
			map.put("name", it.getName());
			list.add(map);
		}
		return list;
	}
}
